// 导入封装的请求数据方法
import { reqGetBannerListData, reqGetCategoryListData, reqGetFloorListData } from "@/api"

export default {
    namespaced: true,
    state: {
        // 1、三级菜单数据
        categoryListData: [],
        // 2、banner数据
        bannerList: [],
        // floor数据
        floorList: []
    },
    mutations: {
        // 1.1、设置三级菜单数据
        setCategoryListData(state, value) {
            state.categoryListData = value.data
        },
        // 2.1、设置bannerList数据
        setBannerListData(state, value) {
            state.floorList = value;
        },
        // 3.1、设置floorList数据
        setFloorList(state, value) {
            state.bannerList = value
        }
    },
    actions: {
        // 1.2、请求三级菜单数据
        async getCategoryListData(context) {
            const result = await reqGetCategoryListData();
            context.commit('setCategoryListData', result)
            // console.log(result);
        },
        // 2.2、请求banner数据
        async getBannerListData({ commit }) {  // 直接将commit从context中解构出来
            const result = await reqGetBannerListData();
            if (result.code === 200) {
                commit('setBannerListData', result.data)
            } else {
                console.log('err:', result.message);
            }
        },
        // 3.2、请求floor数据
        async getFloorListData({ commit }) {
            const result = await reqGetFloorListData();
            if (result.code === 200) {
                commit('setFloorList', result.data)
            } else {
                console.log('err:', result.message);
            }
        }
    },
    getters: {

    }
}